﻿
using TianYuan.Utils.Logging;
using System;
using System.IO;
using StackExchange.Redis;

namespace TianYuan.Logging.Redis
{
    /// <summary>
    /// log4net 日志输出适配器
    /// </summary>
    public class RedisMqLoggerAdapter : LoggerAdapterBase
    {

        ConnectionMultiplexer redis;
        private readonly string _redislogkey = "";
        /// <summary>
        /// 初始化一个<see cref="RedisMqLoggerAdapter"/>类型的新实例
        /// </summary>
        /// <param name="redisconnectstring">redis连接字符串</param>
        /// <param name="redislogkey">redis队列key</param>
        public RedisMqLoggerAdapter(ConfigurationOptions configuration, string redislogkey = "syslog")
        {
            redis = ConnectionMultiplexer.Connect(configuration);
            _redislogkey = redislogkey;
        }

        #region Overrides of LoggerAdapterBase

        /// <summary>
        /// 创建指定名称的缓存实例
        /// </summary>
        /// <param name="name">指定名称</param>
        /// <returns></returns>
        protected override ILog CreateLogger(string name)
        {
            IDatabase db = redis.GetDatabase();
            return new RedisMqtLog(db, _redislogkey);
        }

        #endregion Overrides of LoggerAdapterBase
    }
}